package com.lwj.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class ProjectInterceptor implements HandlerInterceptor {
    @Override
    //拦截处理程序的执行：在 HandlerMapping 确定适当的处理程序对象之后，且在 HandlerAdapter 调用处理程序之前调用。
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle...");
        return true;
    }

    @Override
    //拦截处理程序的执行：在 HandlerAdapter 实际调用处理程序之后，且在 DispatcherServlet 呈现视图之前调用。
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle...");
    }

    @Override
    //请求处理完成后(即呈现视图后)回调，将在处理程序执行的任何结果上调用，从而允许适当的资源清理
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("afterCompletion...");
    }
}
